package com.qianfeng.test.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.qianfeng.test.R;
import com.qianfeng.test.bean.gridview_item_bean.DataEntity;
import com.qianfeng.test.constants.UrlConstans;
import com.qianfeng.test.utils.ImageLoaderHelper;

import java.util.List;

/**
 * Created by Administrator on 15-8-1.
 */
public class GridViewItemAdapter extends AppBaseAdapter<DataEntity> {
    private DisplayImageOptions options;
    public GridViewItemAdapter(List<DataEntity> list, Context context) {
        super(list, context);
        options = ImageLoaderHelper.getInstance().getDisplayImageOptions(R.mipmap.ic_launcher,R.mipmap.ic_launcher);

    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if(convertView==null){
            convertView = inflater.inflate(R.layout.gridview_adapter,parent,false);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        }else{
            vh = (ViewHolder) convertView.getTag();
        }
        vh.summary.setText(list.get(position).getSummary());
       vh.userreview.setText(list.get(position).getUserreview());
        vh.seo_keyword.setText(list.get(position).getSeo_keyword());
        vh.img.setImageResource(R.mipmap.ic_launcher);
        vh.img.setTag(list.get(position).getImage());
        String picUrl = UrlConstans.Url_ADD+list.get(position).getImage();
        ImageLoader.getInstance().displayImage(picUrl,vh.img,options);

        return convertView;
    }
    private static class ViewHolder{
        private ImageView img;
        private TextView summary;
        private TextView userreview;
        private TextView seo_keyword;
        public ViewHolder(View convertView) {
            img = (ImageView) convertView.findViewById(R.id.grid_item_image);
           summary = (TextView) convertView.findViewById(R.id.grid_item_text3);
            userreview = (TextView) convertView.findViewById(R.id.grid_item_text2);
            seo_keyword = (TextView) convertView.findViewById(R.id.grid_item_text1);
        }
    }
}
